package com.hjq.fcloud.other;

import android.content.Context;
import android.webkit.WebView;

import com.hjq.fcloud.BuildConfig;
import com.hjq.fcloud.utils.AppConfigUtils;

public class WebViewLoadHelper {

    public static void commonLoadUrl(WebView view, String url){
        view.loadUrl(addParmsAndloadUrl(url, view.getContext()).toString());
//        view.loadUrl("file:///android_asset/demo.html");
    }

    private static StringBuilder addParmsAndloadUrl(String url, Context context) {
        StringBuilder sb = new StringBuilder(url);
        if (!sb.toString().contains("token=")) {
            String token = AppConfigUtils.getToken();
            if (sb.toString().contains("?")) {
                sb.append("&token=" + token);
            } else {
                sb.append("?token=" + token);
            }
        }

//        if (!sb.toString().contains("customer_id=")) {
//            String customer_id = P.getString(Config.SP_USER_ID);
//            if (sb.toString().contains("?")) {
//                sb.append("&customer_id=" + customer_id);
//            } else {
//                sb.append("?customer_id=" + customer_id);
//            }
//        }

        if (!sb.toString().contains("version=")) {
            String version = BuildConfig.VERSION_NAME;
            if (sb.toString().contains("?")) {
                sb.append("&version=" + version);
            } else {
                sb.append("?version=" + version);
            }
        }
        if (!sb.toString().contains("version_code=")) {
            int version_code = BuildConfig.VERSION_CODE;
            if (sb.toString().contains("?")) {
                sb.append("&version_code=" + version_code);
            } else {
                sb.append("?version_code=" + version_code);
            }
        }
        return sb;
    }
}
